jQuery(document).ready(function() {
		var o;
		o = new timeline();
		o.init({
			"pageNo":"1",
			"pageSize":"10",
			"totalCount":"0",
			"pageUrl":i1510.contextPath+"/admin/wxTextMessage/list.do"
		});
		jQuery("#pageGo").first().click();

});

function timeline(){
	var _this = this;
	this.list = new Array();
	this.pageNo;
	this.pageSize;
	this.totalCount;
	this.pageUrl;
	this.parameter = new Object();
	this.init = function(init_parameter){
		if(typeof init_parameter['pageNo'] != "undefined"){
			_this.pageNo = init_parameter['pageNo'];
		}
		if(typeof init_parameter['pageSize'] != "undefined"){
			_this.pageSize = init_parameter['pageSize'];
		}
		if(typeof init_parameter['totalCount'] != "undefined"){
			_this.totalCount = init_parameter['totalCount'];
		}
		if(typeof init_parameter['pageUrl'] != "undefined"){
			_this.pageUrl = init_parameter['pageUrl'];
		}
		jQuery("#pagePrev").bind("click",_this.pageTurn);
		jQuery("#pageNext").bind("click",_this.pageTurn);
		jQuery("#pageGo").bind("click",_this.pageTurn);
		
	}
	this.pageTurn = function(){
		var clickId = $(this).attr("id");
		var mode = $("#"+clickId).data("mode");
		if(typeof mode != "undefined"){
			if(mode == "prev"){
				var pageNo = $("#pageNo").val();
				if(pageNo == null || pageNo < 2){
					pageNo = _this.pageNo;
				}else{
					pageNo = Number(pageNo) - 1;
				}
				_this.parameter['pageNo'] = pageNo;
				var pageSize = $("#pageSize").val();
				if(pageSize == null || pageSize == "" ){
					pageSize = _this.pageSize;
				}
				_this.parameter['pageSize'] = pageSize;
				
			}else if(mode == "next"){
				var pageNo = $("#pageNo").val();
				if(pageNo == null || pageNo == ""){
					pageNo = _this.pageNo;
				}else{
					pageNo = Number(pageNo) + 1;
				}
				_this.parameter['pageNo'] = pageNo;
				var pageSize = $("#pageSize").val();
				if(pageSize == null || pageSize == ""){
					pageSize = _this.pageSize;
				}
				_this.parameter['pageSize'] = pageSize;
				
			}else if(mode == "go"){
				var pageNo = $("#pageNo").val();
				if(pageNo == null || pageNo == ""){
					pageNo = _this.pageNo;
				}else{
					pageNo = Number(pageNo);
				}
				_this.parameter['pageNo'] = pageNo;
				var pageSize = $("#pageSize").val();
				if(pageSize == null || pageSize == ""){
					pageSize = _this.pageSize;
				}
				_this.parameter['pageSize'] = pageSize;
			}
		}
		jQuery.ajax({
		    type: "GET",
			cache: false,
			data:_this.parameter,
			url: _this.pageUrl,
			dataType:'json',
			success: function(value){
				var data = value.data.listData; 
				var dataStr = "";
				$.each(data, function(i, item) {
					
					dataStr = dataStr + "<li class='timeline-green'>";
					dataStr = dataStr + " <div class='timeline-time'>";
					dataStr = dataStr + "  <span class='date'>"+item.dateStr+"</span> <span class='time'>"+item.timeStr+"</span>";
					dataStr = dataStr + " </div>";
					dataStr = dataStr + " <div class='timeline-icon'><i class='icon-comments'></i>";
					dataStr = dataStr + " </div>";
					dataStr = dataStr + "  <div class='timeline-body'>";
					dataStr = dataStr + "    <h2>[To]"+item.toUserName+"</h2>";
					dataStr = dataStr + "    <div class='timeline-content'>";
					dataStr = dataStr + item.content;
					dataStr = dataStr + "    </div>";
					dataStr = dataStr + "    <div class='timeline-footer'>";
					dataStr = dataStr + "      <a href='#' class='nav-link pull-right'>";
					dataStr = dataStr + "        [From]"+item.fromUserName;
					dataStr = dataStr + "        <i class='m-icon-swapright m-icon-white'></i>";
					dataStr = dataStr + "      </a>";
					dataStr = dataStr + "    </div>";
					dataStr = dataStr + "  </div>";
					dataStr = dataStr + "</li>";
						
				
					//alert("i="+i+"->item="+item.docCreateTime);
				}); 
				$("#pageShow").html(dataStr);
				//分页
				var totalCount = value.data.totalCount;
				var pageNo = value.data.pageNo;
				var pageSize = value.data.pageSize;
				$("#totalCount").html("总记录数:"+totalCount);
				$("#pageNo").val(pageNo);
				$("#pageSize").val(pageSize);
			},		       
	        error: function(jqXHR , textStatus , errorThrown){
	        	alert("--error");
	        }
		})
	}
}